package com.jxwifi.cloud.quickcleanserver.mycenter;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.idroid.widget.LoadDialog;
import com.jxwifi.cloud.quickcleanserver.MainActivity;
import com.jxwifi.cloud.quickcleanserver.R;
import com.jxwifi.cloud.quickcleanserver.app.AccountMgr;
import com.jxwifi.cloud.quickcleanserver.app.CleanBasicActivity;
import com.jxwifi.cloud.quickcleanserver.app.CleaningApplication;
import com.jxwifi.cloud.quickcleanserver.app.UrlPool;
import com.jxwifi.cloud.quickcleanserver.bean.InfoBean;
import com.jxwifi.cloud.quickcleanserver.model.AuzImpl;
import com.jxwifi.cloud.quickcleanserver.okhttp.AuzHttp;
import com.jxwifi.cloud.quickcleanserver.okhttp.DataJson_Cb;
import com.jxwifi.cloud.quickcleanserver.okhttp.Params;
import com.jxwifi.cloud.quickcleanserver.utils.PasswordLogin;
import com.jxwifi.cloud.quickcleanserver.utils.ToastUtils;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 认证列表
 * Created by Administrator on 2020/8/5.
 */

public class CertificationListActivity extends CleanBasicActivity {

    private String TAG = this.getClass().getSimpleName();
    @Bind(R.id.rel_my_personal_data)
    RelativeLayout rel_my_personal_data;
    @Bind(R.id.rel_my_health_certificate)
    RelativeLayout rel_my_health_certificate;
    @Bind(R.id.rel_my_qualification_certificate)
    RelativeLayout rel_my_qualification_certificate;
    @Bind(R.id.tv_my_personal_data)
    TextView tv_my_personal_data;
    @Bind(R.id.tv_my_health_certificate)
    TextView tv_my_health_certificate;
    @Bind(R.id.tv_my_qualification_certificate)
    TextView tv_my_qualification_certificate;
    private String dataAuthen,healthAuthen,proveAuthen;
    private LoadDialog mLoadDialog;
    private String ucHealthCertificateJson;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_certification_list);
        ButterKnife.bind(this);
        mLoadDialog = new LoadDialog(this,"");
        mLoadDialog.show();
        initdata();
    }

    @OnClick({R.id.rel_img_back_pressed, R.id.rel_my_personal_data,R.id.rel_my_health_certificate,R.id.rel_my_qualification_certificate})
    void clickCK(View v){
        Intent intent = new Intent();
        switch (v.getId()){
            case R.id.rel_img_back_pressed:
                onBackPressed();
                break;
            case R.id.rel_my_personal_data:
                intent.setClass(mBaseContext, AuthenticationActivity.class);
                startActivity(intent);
                break;
            case R.id.rel_my_health_certificate:
                intent.setClass(mBaseContext, HealthCertificateActivity.class);
                intent.putExtra("ucHealthCertificateJson",ucHealthCertificateJson);
                startActivity(intent);
                break;
            case R.id.rel_my_qualification_certificate:
                intent.setClass(mBaseContext, ProveListActivity.class);
                startActivity(intent);
                break;
        }
    }

    /**
     * 请求认证列表信息
     */
    public void initdata(){
        Params params=new Params();
        AuzHttp.get(UrlPool.GET_CLEANERCERT_STATUS,params, new DataJson_Cb() {
            @Override
            public void onSuccess(int code, String data) {
                if (code==0){
                    JSONObject jsonObject = JSON.parseObject(data);
                    Log.i(TAG,"initdata ==> data = "+data);
                    dataAuthen = jsonObject.getString("dataAuthen");
                    healthAuthen = jsonObject.getString("healthAuthen");
                    proveAuthen = jsonObject.getString("proveAuthen");
                    if(jsonObject.containsKey("ucHealthCertificate")){
                        ucHealthCertificateJson = jsonObject.getString("ucHealthCertificate");
                        //JSONObject jsonObjectHealth = JSON.parseObject(ucHealthCertificateJson);
                    }
                    Log.i(TAG,"initdata ==> dataAuthen = "+dataAuthen+" healthAuthen = "+healthAuthen+" proveAuthen = "+proveAuthen+" ucHealthCertificateJson = "+ucHealthCertificateJson);
                    initView();
                }else{
                    PasswordLogin.passwordlogin(mBaseContext,TAG,AccountMgr.gettell(mBaseContext),AccountMgr.getpassword(mBaseContext));
                    if (PasswordLogin.mIsLogin){
                        initdata();
                    }
                }
            }

            @Override
            public void onFailure(int errorCode, String msg) {
                mLoadDialog.dismiss();
                Toast toast =Toast.makeText(mBaseContext, msg, Toast.LENGTH_SHORT);
                ToastUtils.showMyToast(toast,3000);
            }
        },TAG);

    }

    /**
     * 初始化界面
     */
    private void initView() {
        //个人资料认证
        if(dataAuthen.equals("wait")){
            tv_my_personal_data.setText("待审核");
            //tv_my_personal_data.setTextColor(Color.YELLOW);
        }else if(dataAuthen.equals("train_apply_ing")){
            tv_my_personal_data.setText("培训审核中");
            //tv_my_personal_data.setTextColor(Color.YELLOW);
        }else if(dataAuthen.equals("company_apply_ing")){
            tv_my_personal_data.setText("公司审核中");
            //tv_my_personal_data.setTextColor(Color.YELLOW);
        }else if(dataAuthen.equals("yes")){
            tv_my_personal_data.setText("通过");
            //tv_my_personal_data.setTextColor(Color.GREEN);
        }else if(dataAuthen.equals("no")){
            tv_my_personal_data.setText("不通过");
            //tv_my_personal_data.setTextColor(Color.RED);
        }
        //健康证
        if(healthAuthen.equals("wait")){
            tv_my_health_certificate.setText("待审核");
            //tv_my_health_certificate.setTextColor(Color.YELLOW);
        }else if(healthAuthen.equals("expired")){
            tv_my_health_certificate.setText("已过期");
            //tv_my_health_certificate.setTextColor(Color.RED);
        }else if(healthAuthen.equals("revoked")){
            tv_my_health_certificate.setText("平台吊销");
            //tv_my_health_certificate.setTextColor(Color.RED);
        }else if(healthAuthen.equals("normal")){
            tv_my_health_certificate.setText("正常");
            //tv_my_health_certificate.setTextColor(Color.GREEN);
        }
        //资质认证
        if(proveAuthen.equals("applying")){
            tv_my_qualification_certificate.setText("申请中");
            //tv_my_qualification_certificate.setTextColor(Color.YELLOW);
        }else if(proveAuthen.equals("expired")){
            tv_my_qualification_certificate.setText("已过期");
            //tv_my_qualification_certificate.setTextColor(Color.RED);
        }else if(proveAuthen.equals("revoked")){
            tv_my_qualification_certificate.setText("平台吊销");
            //tv_my_qualification_certificate.setTextColor(Color.RED);
        }else if(proveAuthen.equals("issued")){
            tv_my_qualification_certificate.setText("已发放");
            //tv_my_qualification_certificate.setTextColor(Color.GREEN);
        }else if(proveAuthen.equals("rejected")){
            tv_my_qualification_certificate.setText("已拒绝");
            //tv_my_qualification_certificate.setTextColor(Color.RED);
        }
        mLoadDialog.dismiss();
    }


}
